package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.SysConsumer;
import com.ruoyi.system.domain.dto.apply.ProductApplyDto;
import com.ruoyi.system.service.ISysConsumerService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysProductApplyMapper;
import com.ruoyi.system.domain.SysProductApply;
import com.ruoyi.system.service.ISysProductApplyService;

/**
 * 产品申请Service业务层处理
 */
@Service
public class SysProductApplyServiceImpl implements ISysProductApplyService 
{
    @Autowired
    private SysProductApplyMapper sysProductApplyMapper;

    @Autowired
    private ISysConsumerService consumerService;

    /**
     * 查询产品申请
     * 
     * @param id 产品申请主键
     * @return 产品申请
     */
    @Override
    public SysProductApply selectSysProductApplyById(Long id)
    {
        return sysProductApplyMapper.selectSysProductApplyById(id);
    }

    /**
     * 查询产品申请列表
     * 
     * @param sysProductApply 产品申请
     * @return 产品申请
     */
    @Override
    public List<SysProductApply> selectSysProductApplyList(SysProductApply sysProductApply)
    {
        return sysProductApplyMapper.selectSysProductApplyList(sysProductApply);
    }

    /**
     * 新增产品申请
     * 
     * @param sysProductApply 产品申请
     * @return 结果
     */
    @Override
    public int insertSysProductApply(SysProductApply sysProductApply,Long userId)
    {
        sysProductApply.setCreateTime(DateUtils.getNowDate());
        SysConsumer byId = consumerService.getById(userId);
        sysProductApply.setBroker(byId.getUserName());
        sysProductApply.setBrokerId(byId.getId());
        return sysProductApplyMapper.insertSysProductApply(sysProductApply);
    }

    /**
     * 修改产品申请
     *
     * @param sysProductApply 产品申请
     * @return 结果
     */
    @Override
    public int updateSysProductApply(SysProductApply sysProductApply)
    {
        return sysProductApplyMapper.updateSysProductApply(sysProductApply);
    }

    @Override
    public int examineApply(ProductApplyDto productApplyDto) {
        SysProductApply sysProductApply = new SysProductApply();
        BeanUtils.copyProperties(productApplyDto,sysProductApply);
        return sysProductApplyMapper.updateSysProductApply(sysProductApply);
    }
}
